import {QuestionInfoPropsType} from "./interface";
import {Form, Input} from "antd";
import {useEffect} from "react";

const {TextArea} = Input
export const PropComponent = (props: QuestionInfoPropsType) => {
    const {title, desc, onChange, disabled} = props
    const [from] = Form.useForm()

    useEffect(() => {
        from.setFieldsValue({title, desc})
    }, [title, desc]);

    function handleValuesChange() {
        if (onChange) onChange(from.getFieldsValue())
    }

    return (
        <Form layout={'vertical'} initialValues={{title, desc}} onValuesChange={handleValuesChange} disabled={disabled}
              form={from}>
            <Form.Item label={'标题'} name={'title'} rules={[{required: true, message: '请输入标题'}]}>
                <Input></Input>
            </Form.Item>
            <Form.Item label={'描述'} name={'desc'}>
                <TextArea></TextArea>
            </Form.Item>
        </Form>
    );
};